package cn.school.test;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.school.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import cn.school.dao.StudentDao;
import cn.school.entity.Student;

public class StudentTest {
	public static void main(String[] args) {
		SqlSession s = MyBatisUtil.get();
		StudentDao dao = s.getMapper(StudentDao.class);
		// 查询
		List<Student> list = dao.findALL(1);
		for (Student r : list) {
			System.out.println(r);
		}

		// 增加
		Student s1 = new Student();
		s1.setAddress("宜秀区大同路111号");
		s1.setBirthday(new Date());
		s1.setEnterdate(new Date());
		s1.setFromcity("安庆");
		s1.setGradeid(14L);
		s1.setPass("123456");
		s1.setQq("3333333");
		s1.setSex("女");
		s1.setSname("王二麻子");
		s1.setTelephone("196112334141");
		s1.setWechat("777777777");
		int i = dao.add(s1);
		System.out.println(i > 0 ? "保存成功" : "保存失败");
		// 删除
		int t = dao.del(19);

		// 修改
		Student s2 = new Student();
		s2.setStuno(1L);
		s2.setAddress("宜秀区大同路111号");
		s2.setBirthday(new Date());
		s2.setEnterdate(new Date());
		s2.setFromcity("安庆");
		s2.setGradeid(14);
		s2.setPass("123456");
		s2.setQq("3333333");
		s2.setSex("女");
		s2.setSname("王二麻子");
		s2.setTelephone("196112334141");
		s2.setWechat("777777777");
		int c = dao.update(s2);
		System.out.println(c > 0 ? "修改成功" : "修改失败");

//分页
		Map map = new HashMap();
		map.put("pageNo", 1);
		map.put("pageSize", 5);
		List<Student> paging = dao.paging(map);
		for (Student r : paging) {
			System.out.println(r);
		}
		// 计数
		int total = dao.total();
		System.out.println(total);

		// 按姓名，QQ，wechat查找学生的信息
		// 方法一
		List<Student> list1 = dao.search("王", "77", "34");
		for (Student r : list1) {
			System.out.println(r);
		}

		s.commit();
		MyBatisUtil.close(s);
	}

}